package com.kevin.spring;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by loli on 2015/6/16.
 */
@Controller
public class UserController {
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public ModelAndView login(String username, String password) {
        if (checkLogin(username, password)) {
            ModelAndView mav = new ModelAndView("succ");
            mav.addObject("username", username);
            mav.addObject("password", password);
            mav.addObject("array", generateArray());
            mav.addObject("list", generateList());
            return mav;
        }

        return new ModelAndView("home");
    }

    private String[] generateArray(){
        String[] array = new String[3];
        array[0]= "111111111";
        array[1]= "222222222";
        array[2]= "333333333";
        return array;
    }

    private List<String> generateList(){
        List<String> list = new ArrayList<String>();
        list.add("111111111");
        list.add("222222222");
        list.add("333333333");
        return list;
    }

    private boolean checkLogin(String username, String password) {
        if (username.equals(password)) {
            return true;
        } else {
            return false;
        }

    }
}
